﻿Option Infer On
Option Explicit On
Option Strict On

Imports System
Imports System.Collections.Generic
Imports System.Xml.Linq
Imports System.Linq
Imports GenDotNet.ObjectModel
Imports <xmlns:orm="http://kadgen.com/KADORM.xsd">
Imports <xmlns:kd="http://kadgen.com/Special.xsd">

Namespace GenInputMetadata
   Public Class CriteriaData
      Inherits BaseData
      Implements ICriteriaData

      Private mObjectData As IObjectData
      Private mCriterions As List(Of ICriterionData)

      Public Shared Function Load( _
               ByVal objectData As ObjectData, _
               ByVal element As XElement) _
               As CriteriaData
         Dim ret = New CriteriaData(objectData.RootData, element)
         ret.mObjectData = objectData
         ret.mCriterions = CriterionData.Load(ret, From x In element.<orm:FilterCriterion>)
         Return ret
      End Function

      Public Shared Function Load( _
               ByVal objectData As ObjectData, _
               ByVal xElements As IEnumerable(Of XElement)) _
               As List(Of ICriteriaData)
         Dim ret = New List(Of ICriteriaData)
         For Each XElement In xElements
            ret.Add(Load(objectData, XElement))
         Next
         Return ret
      End Function

      Private Sub New(ByVal rootData As RootData, _
                      ByVal element As XElement)
         MyBase.New(rootData, element)
      End Sub

      Public ReadOnly Property ObjectData() As IObjectData Implements ICriteriaData.ObjectData
         Get
            Return mObjectData
         End Get
      End Property

      Public ReadOnly Property Name() As String Implements ICriteriaData.Name
         Get
            Return Element.@Name
         End Get
      End Property

      Public ReadOnly Property Criterions() As System.Collections.Generic.List(Of ICriterionData) Implements ICriteriaData.Criterions
         Get
            Return mCriterions
         End Get
      End Property

      Public ReadOnly Property StoredProcedureName() As String Implements ICriteriaData.StoredProcedureName
         Get
            Return Element.@SPName
         End Get
      End Property
   End Class
End Namespace